home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / Macintosh Programmer’s Workshop / MPW 3.1 / SADE 1.1 / SADEScripts / HeapProcs < prev    next >
Text File  |  1990-12-13  |  3KB  |  129 lines

  1. #    Symbolic Application Debugging Environment    1.0 Final
  2. #
  3. #    Copyright Apple Computer, Inc. 1987-1988
  4. #    All rights reserved.
  5.  
  6. ###############################################################################
  7.  
  8. # validate a heap block, and report any problems
  9. func checkblock (zone,lastblock,block,blocksize,blocktype,selfhandle);
  10.     define mp,mpvalue,stderrmsg := "Corrupt heap at %.8X";
  11.  
  12.     if ((blocksize = 0)|((block+blocksize)>lastblock)|((blocksize & $01) = 1))
  13.         printf (stderrmsg,block);
  14.         printf ("   invalid block size = %.8X\n",blocksize);
  15.         return (0);
  16.     end;
  17.     if (blocktype <> 0) then
  18.         if (blocktype < 0) then 
  19.             mp := zone+selfhandle;
  20.             if ((selfhandle = 0)|((selfhandle & $01) = 1)|(mp < zone)|(mp>lastblock))
  21.                 printf (stderrmsg,block);
  22.                 printf ("   invalid self relative handle = %.8X\n",selfhandle);
  23.                 return (0);
  24.             end;
  25.             mpvalue := mp^;
  26.             if ((mpvalue & $0FFFFFFF) <> block+8) then
  27.                 printf (stderrmsg,block);
  28.                 printf ("   master pointer for block at %.8X = %.8X\n",mp,(mpvalue &$0FFFFFFF));
  29.                 printf ("Should = %.8X\n",block+8);
  30.                 return (0);
  31.             end;
  32.             isLocked := ((mpvalue & $80000000) <> 0);
  33.         else
  34.             if (selfhandle <> zone) then
  35.                 printf (stderrmsg,block);
  36.                 printf ("   zone pointer for block = %.8X\n",selfhandle);
  37.                 printf ("Should = %.8X\n",zone);
  38.                 return (0)
  39.             end;
  40.         end;
  41.     end;
  42.     return (1);
  43. end;
  44.  
  45. # Display heap blocks
  46. proc heapdisplay zonetodisplay;
  47.  
  48.     define global valid
  49.     define global islocked
  50.     define nextblock,blocksize,lastblock,selfhandle,blocktype,blockstr;
  51.  
  52.     if nargs = 0 
  53.         zonetodisplay := thezone
  54.     end
  55.  
  56.     nextblock := zonetodisplay+$34;
  57.     lastblock := zonetodisplay^;
  58.     
  59.  
  60.     printf ("location of heap: $%.8X\n",zonetodisplay);
  61.     printf ("last block in heap is: $%.8X\n",lastblock);
  62.  
  63.     lastblock := lastblock + lastblock^;
  64.  
  65.     while (nextblock < lastblock) do
  66.         blocksize := (nextblock^ & $00FFFFFF);
  67.         selfhandle := (nextblock+4)^;
  68.         blocktype := (nextblock^ & $F0000000);
  69.  
  70.         leave If (checkblock (zonetodisplay,lastblock,nextblock,blocksize,blocktype,selfhandle) = 0);
  71.  
  72.         if (blocktype < 0) then
  73.             if isLocked then
  74.                 blockstr := "Locked"
  75.             else
  76.                 blockstr := "Reloc";
  77.             end;
  78.             selfhandle := selfhandle+zonetodisplay;
  79.         elseif (blocktype = 0) then
  80.             blockstr := "Free"
  81.             selfhandle := 0;
  82.         else
  83.             blockstr := "NonReloc"
  84.         end;
  85.  
  86.         printf ("location:$%.8X     size:$%.8X   %8P: $%.8X\n",nextblock,blocksize,blockstr,selfhandle);
  87.         nextblock := nextblock+blocksize;
  88.     end;
  89.     undefine valid
  90.     undefine islocked
  91.  
  92. end;
  93.  
  94. # displays the pointers on the free master pointer list for the current zone
  95. proc showfreemp;
  96. define nextmp;
  97. nextmp := (thezone+8)^;
  98. while (nextmp <> 0) do
  99.     printf ("freemp: $%.8X\n",nextmp);
  100.     nextmp := nextmp^;
  101. end;
  102. end;
  103.  
  104. define mpcount;
  105.  
  106. # counts the pointers on the free master pointer list for the specified zone
  107. func countmp (zone);
  108.     define count,mp;
  109.     mp := (zone+8)^;
  110.     count := 0;
  111.     while (mp <> 0) do
  112.         count := count+1;
  113.         mp := mp^;
  114.     end;
  115.     return count;
  116. end;
  117.  
  118. #displays various information about heaps
  119. proc displayHeapInfo;
  120.     define firstfreemp :=(thezone+8)^
  121.  
  122.     printf ("ApplZone: $%.8X\n",applzone);
  123.     printf ("SysZone: $%.8X\n",syszone);
  124.     printf ("TheZone: $%.8X\n",thezone);
  125.     printf ("First Free MP: $%.8X  Number of free master pointers = %.8d\n",firstfreemp,countmp(TheZone));
  126.     printf ("Free Bytes: $%.8X\n",(thezone+12)^);
  127.     printf ("ApplLimit: $%.8X\n",ApplLimit);
  128. end;
  129.